﻿using System;
using System.Configuration;
using Animoso.Domain;
using FluentNHibernate.Automapping;
using NHibernate.Cfg;
using NHibernate;
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using NHibernate.Tool.hbm2ddl;

namespace Animoso.Data
{
    public class SessionProvider
    {
        private static ISessionFactory _sessionFactory;
        private static Database.Database _database;

        public static ISessionFactory SessionFactory
        {
            get
            {
                if (_sessionFactory == null)
                    CreateSessionFactory();
                return _sessionFactory;
            }
        }

        public static void CreateSessionFactory()
        {
            _database = new Database.Database();
            FluentConfiguration config = _database.GetConfiguration();
            _sessionFactory = config.BuildSessionFactory();
        }

        private SessionProvider()
        {
        }

        public static ISession GetSession()
        {
            return SessionFactory.OpenSession();
        }
    }
}


